﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows.Controls;
using infoMngmntGUI.View;

namespace infoMngmntGUI.Control
{
    public class Controller
    {
        #region Properties

        public delegate void ChangeToUserControl(IView view);
        public event ChangeToUserControl CurrentUserControl;

        public IView CurrentControl { get; private set; }
        public AccessManagement AccessManager { get; private set; }

        #endregion

        #region Construction

        /// <summary>
        /// 
        /// </summary>
        public Controller()
        {
            AccessManager = new AccessManagement();
        }

        #endregion

        #region Public Methods

        /// <summary>
        /// 
        /// </summary>
        /// <param name="control"></param>
        public void AttemptToLoadControl(IView control)
        {
            if (AccessManager.CanAccess(control.minimumAccess))
            {
                CurrentControl = control;

                if (CurrentUserControl != null)
                {
                    CurrentUserControl(control);
                }
            }
            else
            {
                AttemptToLoadControl(new Login(AccessManager));
            }
        }

        #endregion
    }
}
